package com.zhb.lkd.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhb.lkd.base.PageResponse;
import com.zhb.lkd.exception.BusinessException;
import com.zhb.lkd.pojos.entity.VmType;
import com.zhb.lkd.mapper.VmTypeMapper;
import com.zhb.lkd.service.IVmTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 售货机类型表 服务实现类
 * </p>
 *
 * @author haibin
 * @since 2024-08-18
 */
@Service
public class VmTypeServiceImpl extends ServiceImpl<VmTypeMapper, VmType> implements IVmTypeService {
    /**
     * 设备搜索
     * @param pageIndex
     * @param pageSize
     * @param name
     * @return
     */
    @Override
    public PageResponse search(Integer pageIndex, Integer pageSize, String name) {
        //1.检查参数
        if (pageIndex == null || pageSize == null) {
            throw new RuntimeException("参数错误");
        }
        //2.分页查询
        Page<VmType> page = lambdaQuery().like(StrUtil.isNotBlank(name), VmType::getName, name)
                .page(new Page<>(pageIndex, pageSize));
        return new PageResponse(page);
    }

    /**
     * 新增设备类型
     * @param vmType
     */
    @Override
    public void create(VmType vmType) {
        //1.检查参数
        if (StrUtil.isBlank(vmType.getName())) {
            throw new RuntimeException("参数错误");
        }
        //2.保存
        save(vmType);
    }

    /**
     * 删除合作商
     * @param typeId
     */
    @Override
    public void deleteById(String typeId) {
        //1.检查参数
        if (StrUtil.isBlank(typeId)){
            throw new BusinessException(500,"id不能为空");
        }
        //2.删除
        removeById(typeId);
    }
}
